package com.iwhalecloud.bss.kite.cucc.service.attr.handler;

import com.iwhalecloud.bss.kite.common.constant.ServiceOfferConsts;
import com.iwhalecloud.bss.kite.common.util.KiteStringUtils;
import com.iwhalecloud.bss.kite.manager.inst.KiteAttr;
import com.iwhalecloud.bss.kite.manager.inst.KiteInst;
import com.iwhalecloud.bss.kite.service.attr.AttrData;
import com.iwhalecloud.bss.kite.service.attr.handler.AbstractAttrHandler;
import com.ztesoft.bss.common.bo.UserInfo;
import com.ztesoft.bss.common.util.ContextUtil;

/**
 * @Classname DefaultProvCodeAttrHandler
 * @Description 初始值默认操作人省编码
 * @Author zhang.song
 * @Date 2021-03-04 18:10
 */
public class DefaultProvCodeAttrHandler extends AbstractAttrHandler<KiteInst, AttrData> {

    /**
     * 省默认值：操作人省编码
     */
    @Override
    public void after(KiteAttr attr, KiteInst inst, AttrData data) {
        super.after(attr, inst, data);

        // 订购 操作
        if (ServiceOfferConsts.SERVICE_OFFER_ORDER.equals(data.getServiceOfferId())) {
            if (KiteStringUtils.isEmpty(attr.getValue())) {
                UserInfo userInfo = ContextUtil.getLoginInfo().getUserInfo();
                if(userInfo != null) {
                    String provinceId = userInfo.getPostProvinceNbr();
                    if(KiteStringUtils.isNotEmpty(provinceId)) {
                        attr.setValue(provinceId);
                    }
                }
            }
        }
    }
}
